<?php
@session_start();
require_once("../class/mysql.class.php");

if ((isset($_GET["action"])) && ($_GET["action"] == "update"))
{           
            if (empty($_POST['email'])) {
               header("Location:../user.php?action=error");
             } 
             else 
             {
                $obj = new Mysql ();
                $update="UPDATE `user_login` SET `email_login`='".$_POST["email"]."', `password_login`='".$_POST["password"]."',
                `account_login`='".$_POST["account_type"]."' WHERE `id_login`='".$_GET["id_user"]."'";
                $retour=mysql_query($update);
                echo $update; 
                header('location:../user.php?action=user_updated');  
             }

            
}

elseif ((isset($_GET["action"])) && ($_GET["action"] == "delete"))
{

      if (empty($_GET['id_user'])) 
      {
        header("Location:../user.php?action=error");
      } else 
      {
      $obj = new Mysql ();
      $requte="DELETE FROM `user_login` WHERE `id_login`='".$_GET["id_user"]."'";
      $resultat=mysql_query($requte);
      header('location:../user.php?action=user_updated');         
      }                 
      

}

elseif(isset($_POST))
{
    $obj = new Mysql ();
            $obj->set_table("user_login");
            $obj->set_colone("(`*`)");
            $obj -> set_variables(" `email_login` = '" . $_POST["email"] . "' ");
            $values = $obj -> select_enregistrement();

    //if user exist

    if (($_POST['email'])==($values['email_login'])) 
    {
       echo "<br>exist<br>";
       header('location:../user.php?action=user_exist');
    }

    //if user does not exist 

    elseif(($values['email_login'])!==($_POST['email'])) 
    {  
        echo "not exist";

            $obj = new Mysql(); 
            $obj->set_table("user_login");
            $obj->set_colone("(`id_login`, `email_login`, `password_login`, `account_login`)");
            $obj->set_variables("('','".$_POST['email']."','".$_POST['password']."','".$_POST['account_type']."')");
            $requetes=$obj->insert_enregistrement();
            header('location:../user.php?action=user_added');
    }


}
?>